<template>
  <div class="login-wrapper">

    <div class="paper" style="width:450px;margin:0 auto;background:rgba(255,255,255,0.7)">
      <div class="logo_name">
        <img src="../../static/img/tm-logo.png" alt="" class="logoimg">BeMasterⅠ期自动化
      </div>

      <el-form ref="form" :model="form" :rules="rules" @submit.native.prevent="onSubmit" >
        <el-form-item prop="username" class="login_form">
          <el-input v-model="form.username" placeholder="请输入用户名" class="login_input"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" type="password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <div style="text-align: right;" class="loginbtn_box">
          <el-button class="login-button login_btn" :class="{error: loginError}" type="success" native-type="submit" :loading="loading">登录</el-button>
          </div>
        </el-form-item>
        <el-form-item>
          <div style="text-align:center;" class="footer_login">
            版权所有：Copyright  2015 Yikeen. All Rights Reserved.
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  import http from '../api/http'
  export default{
    data () {
      return {
        form: {
          username: '',
          password: ''
        },
        rules: {
          username: [{
            required: true, message: '请输入用户名'
          }],
          password: [{
            required: true, message: '请输入密码'
          }]
        },
        loading: false,
        valid: false,
        loginError: false
      }
    },
    methods: {
      onSubmit () {
        var vm=this;
        vm.$refs.form.validate(valid => {
          if (valid) {
            vm.loading = true;
            setTimeout(function(){
                vm.loading=false;
            },3000);
            http.postData(vm,'/sys/account/signIn', vm.form,function(resp){
              var ret = resp.body;
              if (ret.code == '111') {
                vm.$notify({
                  title: '登录成功!',
                  message: '',
                  type: 'success'
                });
                //存储用户信息到本地
                vm.$store.dispatch('saveCurrentLoginInfo',ret.value).then(() => {
                  vm.$router.replace({path: '/'});
                  location.reload();
                })
              } else {
                vm.$notify.error({
                  title: '登录失败!',
                  message: ret.msg
                })
              }
              vm.loading = false;
            });
          }
        })
      }
    },
    created(){//vue创建后执行

    }
  }

</script>
<style scoped>
  .login-wrapper {
    padding-top:10%;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-size:cover;
    background-image: url('../../static/img/login-bg.jpg');
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-position:center;
  }
  h1 {
    position: relative;
    margin: 0 0 1rem;
  }
  .paper{
    background-color:#FFFFFF;
    padding:50px 30px 10px 30px;
    box-shadow: 0 0px 20px #969696;
    border-radius: 15px;
  }
  .paper .el-input, .el-date-editor {
    max-width: 350px;
  }
  .logo_name{
    text-align: center;
    color:#78c5a5;
    font-size: 20px;
    margin-bottom: 30px;
  }
  .logo_name img{
    width:50px; 
  }
  .logoimg{
    vertical-align: middle;
    margin-right: 10px;
    width:40px;
  }
  .paper[data-v-4bb11f44]{
    padding: 40px 30px 10px 30px;
  }
  .el-button--success{
    background-color: #78c5a5;
    border-color: #78c5a5;
  }
  #app .footer_login{
    color: #78c5a5;
    font-size: 12px;
    line-height: 24px;

  }
.login_form{
  margin-top: 20px;
}
  .el-input__inner:focus{
    border-color: #78c5a5;
  }
  .el-input{
    margin: 0 auto;
  }
  .el-input, .el-input__inner{
    display: block;
  }
  .login_btn{
    width:100%;
  }
  .loginbtn_box{
    width: 350px;
    margin: 0 auto;
  }
  input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill{
    background-color: #fff;
  }
</style>
